package com.rocketmq.consumer.mq;

/**
 * @program: awesome-spring
 * @description: 消费者
 * @author: Alex Wu
 * @createDate: 2025-02-11 09:43
 **/
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;

@Service
@RocketMQMessageListener(topic = "niHao", consumerGroup = "springboot-consumer-group",
        maxReconsumeTimes = 3)  // 配置死信队列最好配置最大消费次数，否则按照16次计算
public class RocketMQConsumer implements RocketMQListener<String> {
    @Override
    public void onMessage(String message) {
        System.out.println("Received message: " + message);
        // 模拟失败
        if ("dlq2".equals(message)) {
            throw new RuntimeException("Over Simulated failure");
        }
    }
}

